
<?php
// print_r($help);
?>

<form action="/<?php echo AppController::APP_NAME?>/Users/save" method="post" id="form">

	<div class="tabbable"> <!-- Only required for left/right tabs -->
	  <ul class="nav nav-tabs">
	    <li class="active"><a href="#tab1" data-toggle="tab">Utente</a></li>
	    <li><a href="#tab2" data-toggle="tab">Anagrafica</a></li>
	  </ul>
	  <div class="tab-content">
	    <div class="tab-pane active" id="tab1">
				    	
			<fieldset>
			    <input type='hidden' name='User[id]' value='<?php echo $user['User']['id'];?>' />
			    <label>Username</label> <input type="text" name="User[username]" value="<?php echo $user['User']['username'];?>" placeholder="Username" disabled>
			    <label>Email</label> <input type="text" name="User[email]" value="<?php echo $user['User']['email'];?>" placeholder="Email" >
			    <label>Gruppo</label>
				<select name='User[group_id]'>
					<option value=''></option>
					<?foreach ($groups as $key => $group) {?>
				  			<option value='<? echo $key?>' <? if($key == $user['User']['group_id']) echo " selected='selected' " ?>  ><? echo $group ?></option>
					<? } ?> 
				</select> 
			    <label>Ultimo accesso</label> <input type="text" name="User[dt_accesso]" value="<?php echo $user['User']['dt_accesso'];?>" placeholder="" disabled>
			    <label>Scadenza</label> <input type="text" name="User[dt_scadenza]" value="<?php echo $user['User']['dt_scadenza'];?>" placeholder="" disabled>
			    <label>Stato</label>
				<select name='User[stato]'>
					<option value=''></option>
					<?foreach ($stati as $key => $stato) {?>
				  			<option value='<? echo $key?>' <? if($key == $user['User']['stato']) echo " selected='selected' " ?>  ><? echo $stato ?></option>
					<? } ?> 
				</select> 
				
				<!-- 	    <label class="checkbox">
			      <input type="checkbox"> Check me out
			    </label> -->
			</fieldset>

	    </div>
	    <div class="tab-pane" id="tab2">

			<fieldset>
			    <input type='hidden' name='Anagrafica[id]' value='<?php echo $user['Anagrafica']['id'];?>' />
			    <label>Nome</label> <input type="text" name="Anagrafica[nome]" value="<?php echo $user['Anagrafica']['nome'];?>" placeholder="nome" >
			    <label>Cognome</label> <input type="text" name="Anagrafica[cognome]" value="<?php echo $user['Anagrafica']['cognome'];?>" placeholder="Cognome" >
			    <div>
			    	<div class="span12">
					    <label><?echo __("Comune")?></label>
			    		<p>
						<select name='Anagrafica[comune_id]' id="comune" style="width: 240px;">
							<option value=''></option>
							<?foreach ($comuni as $comune) {?>
						  			<option data-idprovincia='<?php echo $comune['Comune']['provincia_id']?>' value='<? echo $comune['Comune']['id']?>' <? if($comune['Comune']['id'] == $user['Anagrafica']['comune_id']) echo " selected='selected' " ?>  ><? echo $comune['Comune']['descrizione'] ?></option>
							<? } ?> 
						</select> 
						<label style="display: inline;padding-left: 20px;" id="provincia_regione"  ></label>				
					    </p>
			    		
			    		
			    	</div>
			    	
			    </div>
				
				
			</fieldset>


	    </div>
	  </div>
	</div>

    <p>
		<a href='/<?php echo AppController::APP_NAME?>/Users/add' class="btn" ><i class='icon-plus'></i></a>
		<button type="submit" class="btn btn-primary"><i class='icon-ok'></i></button>
		<a href='/<?php echo AppController::APP_NAME?>/Users/delete/<?php echo $user['User']['id'];?>' class="btn" ><i class='icon-trash'></i></a>
	</p>

	<?php unset($user); ?> 

</form>

<script>
	$(document).ready(function() {
		 $("#comune").select2({minimumInputLength: 3, placeholder: '<?php echo __("Seleziona un comune") ?>',allowClear: true}); 
		 
		 $("#comune").change(function(){
		 	if($("#comune").val()=="")return;	
		 	 idprovincia=$('#comune :selected').data("idprovincia");
			 $.getJSON('/<?php echo AppController::APP_NAME?>/Utils/regioneProvincia/'+idprovincia, function(data) {
		            $("#provincia_regione").html(data["Provincia"]["sigla"]+" - "+data["Regione"]["descrizione"]);
        	});
					 	
		 	
		 });
		 
		 
		 
		 
   });
</script>

